﻿//fs
//#version 150

in vec3 worldSpacePosition;
in vec2 passUV;

uniform sampler2D tex;
uniform vec4 clipPlane = vec4(1, 1, 1, 0); // (x, y, z, w) means (a, b, c, d) in 'aX + bY + cZ + d = 0'.
uniform bool keepGreater = true; // keep the fragments that greater than 0 in the formula.

out vec4 outColor;

void main() {
    vec4 v = vec4(worldSpacePosition, 1) * clipPlane;
    float sum = v.x + v.y + v.z + v.w;
    if ((keepGreater && (sum > 0))
        || ((!keepGreater) && (sum < 0))) {
        outColor = texture(tex, passUV);
    }
    else {
        if (int(gl_FragCoord.x + gl_FragCoord.y) % 2 == 1) discard;

        outColor = texture(tex, passUV);
    }
}